package com.emergency.controller;

import com.emergency.data.param.*;
import com.emergency.http.WrapMapper;
import com.emergency.http.Wrapper;
import com.emergency.service.AffectedPointService;
import com.emergency.service.ExpertGroupService;
import com.emergency.util.ShowUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Validated
@RestController
@RequestMapping("/dispatch")
@Api(tags = "应急调度API")
public class DispatchController {

    @Resource
    private ExpertGroupService expertGroupService;
    @Resource
    private AffectedPointService affectedPointService;


    /**
     * 专家库列表
     *
     * @param dutiesId 职称ID
     * @param industryId 行业ID
     * @param name 姓名
     * @param page 页
     * @param size 大小
     * @return Wrapper
     */
    @ApiOperation("专家库列表")
    @GetMapping("/getExpertGroupList")
    public Wrapper<?> getExpertGroupList(@ApiParam("职称ID") @RequestParam(required = false) Long dutiesId,
                                         @ApiParam("行业ID") @RequestParam(required = false) Long industryId,
                                         @ApiParam("姓名") @RequestParam(required = false) String name,
                                         @ApiParam("页") @RequestParam(required = false) Integer page,
                                         @ApiParam("大小") @RequestParam(required = false, defaultValue = "10") Integer size) {
        return WrapMapper.ok(expertGroupService.getExpertGroupList(dutiesId, industryId, name, page, size));
    }

    @ApiOperation("受灾点列表")
    @GetMapping("/getAffectedPointList")
    public Wrapper<?> getAffectedPointList() {
        return WrapMapper.ok(affectedPointService.getAffectedPointList());
    }

    @ApiOperation("受灾点详情")
    @GetMapping("/getAffectedPointDetails")
    public Wrapper<?> getAffectedPointDetails(@ApiParam("受灾点ID") @RequestParam Long id) {
        return WrapMapper.ok(affectedPointService.getAffectedPointDetails(id));
    }

    @ApiOperation("新增受灾点")
    @PostMapping("/addAffectedPoint")
    public Wrapper<?> addAffectedPoint(@RequestBody AffectedPointParam affectedPointParam) {

        return WrapMapper.ok(affectedPointService.addAffectedPoint(affectedPointParam));
    }

    @ApiOperation("删除受灾点")
    @PostMapping("/delAffectedPoint")
    public Wrapper<?> delAffectedPoint(@ApiParam("受灾点ID") @RequestParam Long id) {

        return WrapMapper.ok(affectedPointService.delAffectedPoint(id));
    }

    @ApiOperation("受灾点调度范围搜索")
    @PostMapping("/scopeScheduleSearch")
    public Wrapper<?> scopeScheduleSearch(@ApiParam("受灾点id") @RequestParam Long affectedPointId,
                                          @ApiParam("调度范围") @RequestParam Integer scheduleScope) {
        return WrapMapper.ok(affectedPointService.scopeScheduleSearch(affectedPointId,scheduleScope));
    }

    @ApiOperation("受灾点范围搜索调度提交")
    @PostMapping("/scheduleScopeAffected")
    public Wrapper<?> scheduleScopeAffected(@RequestBody ScheduleScopeAffectedParam scheduleScopeAffectedParam) {
        return WrapMapper.ok(affectedPointService.scheduleScopeAffected(scheduleScopeAffectedParam));
    }

    @ApiOperation("物资类型")
    @GetMapping("/getSuppliesTypeList")
    public Wrapper<?> getSuppliesTypeList() {
        return WrapMapper.ok(affectedPointService.getSuppliesTypeList());
    }

    @ApiOperation("救援队类型")
    @GetMapping("/getRescueTeamTypeList")
    public Wrapper<?> getRescueTeamTypeList() {
        return WrapMapper.ok(affectedPointService.getRescueTeamTypeList());
    }

    @ApiOperation("受灾点按需筛选救援队搜索")
    @PostMapping("/requiredScheduleSearch/team")
    public Wrapper<?> requiredScheduleSearchTeam(@ApiParam("受灾点id") @RequestParam Long affectedPointId,
                                                 @ApiParam("类型") @RequestParam(required = false) Integer typeId) {
        return WrapMapper.ok(affectedPointService.requiredScheduleSearchTeam(affectedPointId,typeId));
    }

    @ApiOperation("受灾点按需筛选避灾点搜索")
    @PostMapping("/requiredScheduleSearch/rescue")
    public Wrapper<?> requiredScheduleSearchRescue(@ApiParam("受灾点id") @RequestParam Long affectedPointId,
                                                   @ApiParam("人数") @RequestParam(required = false) Integer affectedCount) {
        return WrapMapper.ok(affectedPointService.requiredScheduleSearchRescue(affectedPointId,affectedCount));
    }

    @ApiOperation("确认专家通知")
    @GetMapping("/expert/confirmNotice")
    public void expertConfirmNotice(HttpServletResponse response,@ApiParam("通知id") @RequestParam Long noticeId) {
        boolean b = affectedPointService.expertConfirmNotice(noticeId);
        if(b) {
            ShowUtil.showPic(response);
        }
    }

    @ApiOperation("专家通知列表")
    @GetMapping("/expert/noticeList")
    public Wrapper<?> expertNoticeList(@ApiParam("受灾点id") @RequestParam Long affectedPointId) {
        return WrapMapper.ok(affectedPointService.expertNoticeList(affectedPointId));
    }

    @ApiOperation("通知专家")
    @PostMapping("/expert/addNotice")
    public Wrapper<?> addExpertNotice(@Validated @RequestBody NoticeParam noticeParam) {
        return WrapMapper.ok(affectedPointService.addExpertNotice(noticeParam));
    }

    @ApiOperation("受灾点按需筛选调度救援队提交")
    @PostMapping("/scheduleRequireAffected/team")
    public Wrapper<?> scheduleRequireAffectedTeam(@RequestBody ScheduleRequireAffectedTeamParam scheduleRequireAffectedTeamParam) {
        return WrapMapper.ok(affectedPointService.scheduleRequireAffectedTeam(scheduleRequireAffectedTeamParam));
    }

    @ApiOperation("受灾点按需筛选调度避灾点提交")
    @PostMapping("/scheduleRequireAffected/settlement")
    public Wrapper<?> scheduleRequireAffectedSettlement(@RequestBody ScheduleRequireAffectedSettlementParam scheduleRequireAffectedSettlementParam) {
        return WrapMapper.ok(affectedPointService.scheduleRequireAffectedSettlement(scheduleRequireAffectedSettlementParam));
    }

    @ApiOperation("受灾点按需筛选调度物资点提交")
    @PostMapping("/scheduleRequireAffected/supplies")
    public Wrapper<?> scheduleRequireAffectedSupplies(@RequestBody ScheduleRequireAffectedSuppliesParam scheduleRequireAffectedSuppliesParam) {
        return WrapMapper.ok(affectedPointService.scheduleRequireAffectedSupplies(scheduleRequireAffectedSuppliesParam));
    }

    @ApiOperation("受灾点按需筛选物资点搜索")
    @PostMapping("/requiredScheduleSearch/supplies")
    public Wrapper<?> requiredScheduleSearchSupplies(@Valid @RequestBody DispatchRequiredSuppliesParam param) {
        if(param == null) {
            return WrapMapper.error("缺少必要参数");
        }
        return WrapMapper.ok(affectedPointService.requiredScheduleSearchSupplies(param));
    }
}
